package vm;

/**
 * @author zzb
 * @since 2021-01-21
 */
public class ReferenceCountingGC {

  public Object instance = null;
  private final static int _1MB = 1024 * 1024;
  private byte[] bigSize = new byte[2 * _1MB];

  public static void testGC() {
    ReferenceCountingGC objA = new ReferenceCountingGC();
    ReferenceCountingGC objB = new ReferenceCountingGC();
    objA.instance = objB;
    objB.instance = objA;

    objA = null;
    objB = null;

    System.gc();
  }

  public static void main(String[] args) {
    testGC();
  }
  /**
   * [0.002s][warning][gc] -XX:+PrintGCDetails is deprecated. Will use -Xlog:gc* instead.
   * [0.005s][info   ][gc,heap] Heap region size: 1M
   * [0.010s][info   ][gc     ] Using G1
   * [0.010s][info   ][gc,heap,coops] Heap address: 0x0000000703e00000, size: 4034 MB, Compressed Oops mode: Zero based, Oop shift amount: 3
   * [0.109s][info   ][gc,task      ] GC(0) Using 6 workers of 10 for full compaction
   * [0.109s][info   ][gc,start     ] GC(0) Pause Full (System.gc())
   * [0.109s][info   ][gc,phases,start] GC(0) Phase 1: Mark live objects
   * [0.110s][info   ][gc,stringtable ] GC(0) Cleaned string and symbol table, strings: 2849 processed, 3 removed, symbols: 26356 processed, 0 removed
   * [0.110s][info   ][gc,phases      ] GC(0) Phase 1: Mark live objects 0.682ms
   * [0.110s][info   ][gc,phases,start] GC(0) Phase 2: Prepare for compaction
   * [0.110s][info   ][gc,phases      ] GC(0) Phase 2: Prepare for compaction 0.260ms
   * [0.110s][info   ][gc,phases,start] GC(0) Phase 3: Adjust pointers
   * [0.110s][info   ][gc,phases      ] GC(0) Phase 3: Adjust pointers 0.234ms
   * [0.110s][info   ][gc,phases,start] GC(0) Phase 4: Compact heap
   * [0.111s][info   ][gc,phases      ] GC(0) Phase 4: Compact heap 0.237ms
   * [0.112s][info   ][gc,heap        ] GC(0) Eden regions: 4->0(4)
   * [0.112s][info   ][gc,heap        ] GC(0) Survivor regions: 0->0(0)
   * [0.112s][info   ][gc,heap        ] GC(0) Old regions: 0->4
   * [0.112s][info   ][gc,heap        ] GC(0) Humongous regions: 6->0
   * [0.112s][info   ][gc,metaspace   ] GC(0) Metaspace: 6325K->6325K(1056768K)
   * [0.112s][info   ][gc             ] GC(0) Pause Full (System.gc()) 9M->0M(14M) 3.101ms
   * [0.112s][info   ][gc,cpu         ] GC(0) User=0.00s Sys=0.02s Real=0.00s
   * [0.113s][info   ][gc,heap,exit   ] Heap
   * [0.113s][info   ][gc,heap,exit   ]  garbage-first heap   total 14336K, used 977K [0x0000000703e00000, 0x0000000800000000)
   * [0.113s][info   ][gc,heap,exit   ]   region size 1024K, 1 young (1024K), 0 survivors (0K)
   * [0.113s][info   ][gc,heap,exit   ]  Metaspace       used 6349K, capacity 6379K, committed 6528K, reserved 1056768K
   * [0.113s][info   ][gc,heap,exit   ]   class space    used 553K, capacity 570K, committed 640K, reserved 1048576K
   */
}
